package com.globalwave.pos.inventory.entity;

import javax.persistence.Column;

import com.globalwave.base.annotations.Comparison;


public class InventoryTransactionSO  {
	
	private static final long serialVersionUID = 1L;
	
	public static final String INVENTORY_TRANS_CODE_SHIPMENT = "S" ;
	public static final String INVENTORY_TRANS_CODE_MORTGAGED = "M" ;

    public final static StringBuffer MAX_INVENTORY_TRANSACTION_ID = new StringBuffer(
        " select max(id) as max, min(id) as min " +
        "   from TSTB_INVENTORY_TRANSACTION " ); 
    
    public final static String MOVE_TRANSACTIONS_TO_HISTORY = 
    	  " INSERT INTO HSTB_INVENTORY_TRANSACTION"
    	+ " ("
    	+ "     ID"
    	+ "   , REFERENCE_ID"
    	+ "   , LEVEL1_NUMBER"
    	+ "   , LEVEL2_NUMBER"
    	+ "   , REFERENCE_SOURCE"
    	+ "   , WAREHOUSE_CODE"
    	+ "   , LOCATION_NUMBER"
    	+ "   , BATCH_NUMBER"
    	+ "   , STOCK_ITEM_NUMBER"
    	+ "   , TRANSACTION_DATE_TIME"
    	+ "   , TRANSACTION_QUANTITY"
    	+ "   , TRANSACTION_CODE"
    	+ "   , TRANSFER_STATUS"
    	+ "   , CREATED_TIMESTAMP"
    	+ "   , MODIFIED_TIMESTAMP"
    	+ " ) select" 
    	+ "     ID"
    	+ "   , REFERENCE_ID"
    	+ "   , LEVEL1_NUMBER"
    	+ "   , LEVEL2_NUMBER"
    	+ "   , REFERENCE_SOURCE"
    	+ "   , WAREHOUSE_CODE"
    	+ "   , LOCATION_NUMBER"
    	+ "   , BATCH_NUMBER"
    	+ "   , STOCK_ITEM_NUMBER"
    	+ "   , TRANSACTION_DATE_TIME"
    	+ "   , TRANSACTION_QUANTITY"
    	+ "   , TRANSACTION_CODE"
    	+ "   , TRANSFER_STATUS"
    	+ "   , CREATED_TIMESTAMP"
    	+ "   , MODIFIED_TIMESTAMP"
    	+ " from TSTB_INVENTORY_TRANSACTION"
    	+ " where ID>=? and ID<=?"
    	+ "   and transaction_date_time>=? and transaction_date_time<=?" ;
    
    public static String DELETE_TEMP_TRANSACTIONS = 
    	   " delete from TSTB_INVENTORY_TRANSACTION "
    	 + " where ID>=? and ID<=?"
    	 + "   and transaction_date_time>=? and transaction_date_time<=?" ;
    
    public static String FETCH_TRANSACTIONS_FROM_INTERFACE = 
    	"INSERT INTO TSTB_INVENTORY_TRANSACTION"
    	+ "("
    	+ "    ID"
    	+ "  , REFERENCE_ID"
    	+ "  , LEVEL1_NUMBER"
    	+ "  , LEVEL2_NUMBER"
    	+ "  , REFERENCE_SOURCE"
    	+ "  , WAREHOUSE_CODE"
    	+ "  , LOCATION_NUMBER"
    	+ "  , BATCH_NUMBER"
    	+ "  , STOCK_ITEM_NUMBER"
    	+ "  , TRANSACTION_DATE_TIME"
    	+ "  , TRANSACTION_QUANTITY"
    	+ "  , TRANSACTION_CODE"
    	+ "  , TRANSFER_STATUS"
    	+ "  , CREATED_TIMESTAMP"
    	+ "  , MODIFIED_TIMESTAMP"
    	+ ")"
    	+ "select "
    	+ "    TSSQ_INVENTORY_TRANSACTION_ID.nextval"
    	+ "  , ID   as REFERENCE_ID"
    	+ "  , NULL as LEVEL1_NUMBER"
    	+ "  , NULL as LEVEL2_NUMBER"
    	+ "  , TRANSACTION_CODE as REFERENCE_SOURCE"
    	+ "  , WAREHOUSE_CODE"
    	+ "  , NULL as LOCATION_NUMBER"
    	+ "  , NULL as BATCH_NUMBER"
    	+ "  , STOCK_ITEM_NUMBER"
    	+ "  , TRANSACTION_DATE_TIME"
    	+ "  , TRANSACTION_QUANTITY"
    	+ "  , 'I' as TRANSACTION_CODE"
    	+ "  , 0   as TRANSFER_STATUS"
    	+ "  , current_timestamp as CREATED_TIMESTAMP"
    	+ "  , current_timestamp as MODIFIED_TIMESTAMP"
    	+ "from IFTB_INVENTORY_TRANSACTION"
    	+ "where TRANSFER_STATUS=0 and (TRANSACTION_QUANTITY is not null or TRANSACTION_QUANTITY!=0)"
    	+ "  and id between ? and ?" ;
    
    public static String UPDATE_INF_TRANS_STATUS_TO_FETCHED =
    	   " update IFTB_INVENTORY_TRANSACTION"
    	 + "    set TRANSFER_STATUS=1"
    	 + " where TRANSFER_STATUS=0 and (TRANSACTION_QUANTITY is not null or TRANSACTION_QUANTITY!=0)"
    	 + "   and id between ? and ?"
    	;
    
    
    public static StringBuffer MAX_INVENTORY_TRANSACTION_INF_ID = 
    	   new StringBuffer("select max(id) as max, min(id) as min from IFTB_INVENTORY_TRANSACTION"
    	 + " where TRANSFER_STATUS=0 and (TRANSACTION_QUANTITY is not null or TRANSACTION_QUANTITY!=0)") ;
    
    
    @Column(name="transaction_date")
    @Comparison(operator=">=")
    private Long transactionDateFrom ;

    @Column(name="transaction_date")
    @Comparison(operator="<=")
    private Long transactionDateTo ;

	public Long getTransactionDateFrom() {
		return transactionDateFrom;
	}

	public void setTransactionDateFrom(Long transactionDateFrom) {
		this.transactionDateFrom = transactionDateFrom;
	}

	public Long getTransactionDateTo() {
		return transactionDateTo;
	}

	public void setTransactionDateTo(Long transactionDateTo) {
		this.transactionDateTo = transactionDateTo;
	}
    
    
    
}